package com.huika.dealontop.control.myinfo.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseAda;
import com.huika.dealontop.support.domain.SelectLanguageBean;

import java.util.ArrayList;

/**
 * @author chenyuan
 * @description：语言选择适配器
 * @date 2015年11月16日 上午11:25:04
 */
public class SelectLanguageLvAdapter extends BaseAda<SelectLanguageBean> {
    private ArrayList<ImageView> ivs;

    public SelectLanguageLvAdapter(Context context) {
        super(context);
        ivs = new ArrayList<ImageView>();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_languagelv, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        SelectLanguageBean bean = getItem(position);
        vh.tvLanguage.setText(bean.getLang());
        vh.ivIcon.setTag(bean.getCountryCode());
        ivs.add(vh.ivIcon);
        return convertView;
    }

    class ViewHolder {
        public TextView tvLanguage;
        public ImageView ivIcon;

        public ViewHolder(View convertView) {
            tvLanguage = (TextView) convertView.findViewById(R.id.tv_language);
            ivIcon = (ImageView) convertView.findViewById(R.id.iv_language);
        }
    }

    public void setIcon(String lang) {
        if (TextUtils.isEmpty(lang)) {
//			lang = SelectLanguageUtils.LANG_AUTO;
        }
        for (int i = 0; i < ivs.size(); i++) {
            ImageView iv = ivs.get(i);
            String countryCode = (String) iv.getTag();
            if (!lang.equals(countryCode)) {
                iv.setVisibility(View.GONE);
            } else {
                iv.setVisibility(View.VISIBLE);
            }
        }
    }

}
